#include <iostream>
#include "sharecomm.h"
#include <unistd.h>
#include "Time.h"

#include "Fifo.h"
using namespace std;

int main()
{
    // 1.创建key
    //  key_t k = ftok(path.c_str(), projId);

    // cout << "k:" << k << endl;
    // //2.创建共享内存
    // int shmid = shmget(k, gshmsize, IPC_CREAT | IPC_EXCL);
    // if (shmid < 0)
    // {
    //     cerr << "shmget error" << endl;
    // }
    // //sleep(10);
    // //3.共享内存挂接到自己的地址空间中
    // shmctl(shmid, IPC_RMID, nullptr);
    // cout << "shmid" << shmid << endl;
    shm.CreateShm();
    shm.Attach();
    // sleep(10);
    gpipe.OpenPipeForRead();
    cout << "serve attch done" << endl;
    struct data *stringinfo = (struct data *)shm.GetAdd();
    // printf("serve 虚拟地址:%p\n", stringinfo);
    // sleep(10);

    while (true)
    {
        gpipe.wait();
        printf("statuc::%s\n", stringinfo->status);
        printf("lasttime:%s\n", stringinfo->lasttime);
        printf("image:%s\n", stringinfo->image);
        strcpy(stringinfo->status, "过期");

        sleep(3);
    }
    shm.DetachShm();
    cout << "serve detach done" << endl;
    sleep(10);
    shm.DeletaShm();
    cout << "serve delete done" << endl;
    return 0;
}